<?php

require_once 'social/SocialAbstract.php';
require_once 'social/SocialInterface.php';
require_once 'social/SocialFacebook.php';


class Social
{
	protected $_aConfig;

	/**
	 * @var SocialInterface[]
	 */
	protected $_aHandlers = array();

	public function __construct()
	{
		$this->_aConfig = Yii::app()->params['social'];
	}

	/**
	 * @param SocialInterface $oHandler
	 * @return $this
	 */
	public function setHandler(SocialInterface $oHandler)
	{
		$class = get_class($oHandler);

		$oHandler->setConfig($this->_aConfig[$class]);

		$this->_aHandlers[$class] = $oHandler;

		return $this;
	}

	public function init()
	{
		foreach($this->_aHandlers as $oHandler)
		{
			$oHandler->init();
		}

		return $this;
	}

	/**
	 * @param string $className
	 * @return SocialInterface | null
	 */
	public function getHandler($className)
	{
		if(isset($this->_aHandlers[$className]))
			return $this->_aHandlers[$className];

		return null;
	}

	public function post($title, $description, $link = '')
	{
		foreach($this->_aHandlers as $oHandler)
		{
			$oHandler->postToWall($title, $description, $link);
		}

		return $this;
	}


} 